package com.learning.spring.cloud.alibaba.hystrix.detail.web.controller;

import com.learning.spring.cloud.alibaba.hystrix.detail.web.service.OrderHystrixFeignService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * ClassName: UserController
 * Description:
 * Date: 2021/7/25 23:03 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
@Slf4j
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    OrderHystrixFeignService orderHystrixFeignService;

    /**
     * 监控地址 - http://localhost:port/hystrix.stream
     * <p>
     * 1、hystrix 的 hystrix-metrics-event-stream 模块，可以将监控的指标信息以 text/event-stream 的格式暴露给外部系统
     * 2、spring-cloud-starter-netflix-hystrix 包含了 hystrix-metrics-event-stream 模块
     * 3、默认 feign 集成 hystrix 熔断是不需要添加 @EnableHystrix 注解的，但是如需监控则需要手动添加
     * 4、依赖于端点监控的 spring-boot-actuator 模块
     *
     * @param id
     * @return
     */
    @GetMapping("/query/{id}")
    @HystrixCommand
    public List<String> queryOrderByUserId(@PathVariable("id") Long id) {
        return orderHystrixFeignService.queryOrderByUserId(id);
    }
}
